package com.neudeu.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.neudeu.dto.GoodsInsert;
import com.neudeu.dto.GoodsResult;
import com.neudeu.dto.UserLogin;
import com.neudeu.entity.CategoryEntity;
import com.neudeu.entity.GoodsEntity;
import com.neudeu.entity.UserEntity;
import com.neudeu.page.Page;
import com.neudeu.service.CategoryService;
import com.neudeu.service.GoodsService;
import com.neudeu.service.UserService;

@Controller
@RequestMapping("goods")
public class GoodsController {
	
	@Autowired
	private GoodsService goodsservice;
	
	@GetMapping("list")
	public String list(Model model) {
		List<GoodsResult> goods=goodsservice.all();
		model.addAttribute("goods", goods);
		return "goodslist";
	} 
	@GetMapping("add")
	public String add() {
		
		return "goodsadd";
	} 
	
	@PostMapping("insert")
	public String insert(GoodsInsert goods,HttpServletRequest request) {
		String path=request.getServletContext().getRealPath("/")+"upload/";
		goodsservice.modify(goods, path);
	
		   return "redirect:/goods/list";
		
	} 
	
}
